﻿Public Class TMySystemViews
    Inherits TCustomMyObjects

    Friend Sub New(ByVal AOwner As TMyDatabase)
        MyBase.New(AOwner)
    End Sub

    Public Overrides Sub Refresh()
        Dim item As TMySystemView
        _List.Clear()
        MyQuery.Clear()
        MyQuery.SQL.AppendLine("SELECT")
        MyQuery.SQL.AppendLine(" TABLE_CATALOG")
        MyQuery.SQL.AppendLine(",TABLE_SCHEMA")
        MyQuery.SQL.AppendLine(",TABLE_NAME")
        MyQuery.SQL.AppendLine(",TABLE_TYPE")
        MyQuery.SQL.AppendLine(",ENGINE")
        MyQuery.SQL.AppendLine(",VERSION")
        MyQuery.SQL.AppendLine(",ROW_FORMAT")
        MyQuery.SQL.AppendLine(",TABLE_ROWS")
        MyQuery.SQL.AppendLine(",AVG_ROW_LENGTH")
        MyQuery.SQL.AppendLine(",DATA_LENGTH")
        MyQuery.SQL.AppendLine(",MAX_DATA_LENGTH")
        MyQuery.SQL.AppendLine(",INDEX_LENGTH")
        MyQuery.SQL.AppendLine(",DATA_FREE")
        MyQuery.SQL.AppendLine(",AUTO_INCREMENT")
        MyQuery.SQL.AppendLine(",CREATE_TIME")
        MyQuery.SQL.AppendLine(",UPDATE_TIME")
        MyQuery.SQL.AppendLine(",CHECK_TIME")
        MyQuery.SQL.AppendLine(",TABLE_COLLATION")
        MyQuery.SQL.AppendLine(",CHECKSUM")
        MyQuery.SQL.AppendLine(",CREATE_OPTIONS")
        MyQuery.SQL.AppendLine(",TABLE_COMMENT")
        MyQuery.SQL.AppendLine("FROM")
        MyQuery.SQL.AppendLine(" information_schema.tables")
        MyQuery.SQL.AppendLine("where")
        MyQuery.SQL.AppendLine("table_schema=?table_schema")
        MyQuery.SQL.AppendLine("and table_type like '%SYSTEM VIEW%'")
        MyQuery.SQL.AppendLine("order by")
        MyQuery.SQL.AppendLine(" table_name")
        MyQuery.DeclareAndSet("table_schema", Me.DatabaseName)
        MyQuery.Execute()
        While Not MyQuery.Eof
            item = New TMySystemView(Me, MyQuery.FieldAsString("table_name"))
            item._TableCatalog = MyQuery.FieldAsString("table_catalog")
            item._TableSchema = MyQuery.FieldAsString("table_schema")
            item._TableName = MyQuery.FieldAsString("table_name")
            item._TableType = MyQuery.FieldAsString("table_type")
            item._Engine = MyQuery.FieldAsString("engine")
            item._Version = MyQuery.FieldAsInteger("version")
            item._RowFormat = MyQuery.FieldAsString("row_format")
            item._TableRows = MyQuery.FieldAsInteger("table_rows")
            item._AvgRowLength = MyQuery.FieldAsInteger("avg_row_length")
            item._DataLength = MyQuery.FieldAsInteger("data_length")
            item._MaxDataLength = MyQuery.FieldAsInteger("max_data_length")
            item._IndexLength = MyQuery.FieldAsInteger("index_length")
            item._DataFree = MyQuery.FieldAsInteger("data_free")
            item._AutoIncrement = MyQuery.FieldAsInteger("auto_increment")
            item._CreateTime = MyQuery.FieldAsDateTime("create_time")
            item._UpdateTime = MyQuery.FieldAsDateTime("update_time")
            item._CheckTime = MyQuery.FieldAsDateTime("check_time")
            item._TableCollation = MyQuery.FieldAsString("table_collation")
            item._Checksum = MyQuery.FieldAsInteger("checksum")
            item._CreateOptions = MyQuery.FieldAsString("create_options")
            item._TableComment = MyQuery.FieldAsString("table_comment")
            _List.Add(item)
            MyQuery.MoveNext()
        End While
        MyQuery.Close()
    End Sub

End Class
